package com.fh.gs;

import com.fh.gs.config.MyCustomRule;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.netflix.ribbon.RibbonClient;
import org.springframework.context.annotation.Bean;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.web.client.RestTemplate;

/**
 * @FileName : GoodsApp
 * @Description :
 * @Author : fh
 * @Date : 2020/11/18 10:34
 * @Version : 1.0.0
 */
@SpringBootApplication
@MapperScan("com.fh.gs.dao")
@EnableTransactionManagement
@EnableEurekaClient
//name 可以随意起名，表示ribbon客户端名  configuration 配置使用的负载均衡类
@RibbonClient(name = "goodsRibbon",configuration = MyCustomRule.class)
public class GoodsApp {

    public static void main(String[] args) {
        SpringApplication.run(GoodsApp.class,args);
    }

    /**
     * 初始化 RestTemplate，交给spring容器管理
     * @return
     */
    @Bean
    @LoadBalanced //负责均衡注解
    public RestTemplate restTemplate(){
        return new RestTemplate();
    }
}
